import 'package:event_bus/event_bus.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:wangziyi_app/constans/constans.dart';
import 'package:wangziyi_app/constans/text_stype.dart';
import 'package:wangziyi_app/constans/toast.dart';
import 'package:wangziyi_app/main.dart';
import 'package:wangziyi_app/pages/app_theme_color.dart';
import 'package:wangziyi_app/pages/personal_information.dart';
import 'package:wangziyi_app/pages/setting_address.dart';
import 'package:wangziyi_app/scoped_model/app_theme_color_model.dart';
import 'package:wangziyi_app/utils/eventbus_utils.dart';
import 'package:wangziyi_app/widgets/my_text.dart';

class Setting extends StatefulWidget {
  @override
  _SettingState createState() => _SettingState();
}

class _SettingState extends State<Setting> {
  List SettingTitles = [
    "我的收货地址",
    "账户与安全",
    "支付设置",
    "音效与通知",
    "主题颜色",
    "隐私",
    "通用",
    "问题反馈",
    "关于",
    "切换账号",
    "退出登录",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("设置"),
        centerTitle: true,
      ),
      body: Container(
        child: ListView.separated(
          // shrinkWrap: true,
          // physics: NeverScrollableScrollPhysics(),
          itemBuilder: (BuildContext context, int index) {
            if (index == 0) {
              return GestureDetector(
                child: Container(
                    child: ListTile(
                  leading: ClipOval(
                    child: Image.asset('assets/images/touxiang.png'),
                  ),
                  title: Text(
                    "王子异",
                    style: Text_Style().setTitle(Colors.black),
                  ),
                  subtitle: Text("我就是我。不一样的烟火"),
                )),
                onTap: () {
                  Navigator.push(context, MaterialPageRoute(builder: (_) {
                    return PersonalInformation();
                  }));
                },
              );
            }
            index -= 1;

            return Container(
              child: ListTile(
                title: _text(
                  index,
                  MyText(SettingTitles[index], Colors.black, 16, 1),
                ),
                trailing: _icon(index),
                onTap: () {
                  //收货地址
                  if (index == 0) {
                    Navigator.push(context, MaterialPageRoute(builder: (_) {
                      return MyAddress();
                    }));
                  }
                  if (index == 4) {
                    Navigator.push(context, MaterialPageRoute(builder: (_) {
                      return AppThemeColorItem();
                    }));
                  }
                },
              ),
            );
          },
          separatorBuilder: (context, index) {
            if (index == 1) {
              return Divider(
                height: 10,
                thickness: 10,
              );
            }
            if (index == 3) {
              return Divider(
                height: 10,
                thickness: 10,
              );
            }
            if (index == 7) {
              return Divider(
                height: 10,
                thickness: 10,
              );
            }
            if (index == 9) {
              return Divider(
                height: 10,
                thickness: 10,
              );
            }
            return Divider(
              height: 0,
            );
          },
          itemCount: SettingTitles.length + 1,
        ),
      ),
    );
  }

  _text(index, widget) {
    if (index == 9) {
      return Center(
        child: widget,
      );
    } else if (index == 10) {
      return Center(
        child: widget,
      );
    } else {
      return widget;
    }
  }

  _icon(int index) {
    if (index == 9) {
    } else if (index == 10) {
    } else {
      return Icon(Icons.keyboard_arrow_right);
    }
  }
}
